package com.ideaaedi.zoo.example.springboot.seata_sharding.beta.service;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.ideaaedi.zoo.example.springboot.seata_sharding.beta.mapper.PayRecordMapper;
import com.ideaaedi.zoo.example.springboot.seata_sharding.beta.mapper.TransRecordMapper;
import com.ideaaedi.zoo.example.springboot.seata_sharding.beta.po.PayRecordPO;
import com.ideaaedi.zoo.example.springboot.seata_sharding.beta.po.TransRecordPO;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class BizShardingService {
    
    @Resource
    TransRecordMapper transRecordMapper;
    
    @Resource
    PayRecordMapper payRecordMapper;
    
    @Transactional(rollbackFor = Exception.class)
    public void insertSomeShardingData() {
        prepareData();
    }
    
    void prepareData() {
        // 插入数据
        transRecordMapper.insert(TransRecordPO.builder()
                .id(IdWorker.getId())
                .transDate("2024-08-29")
                .remark("Beta 备注A")
                .build());
        payRecordMapper.insert(PayRecordPO.builder()
                .id(IdWorker.getId())
                .payDate("2024-08-29")
                .amount("Beta 9.4")
                .build());
    
        transRecordMapper.insert(TransRecordPO.builder()
                .id(IdWorker.getId())
                .transDate("2024-09-30")
                .remark("Beta 备注B")
                .build());
        payRecordMapper.insert(PayRecordPO.builder()
                .id(IdWorker.getId())
                .payDate("2024-09-30")
                .amount("Beta 7.7")
                .build());
    }
}
